package com.way.designpatterncodepratice.singleton;

/**
 * @author liangliwei 80551025
 * @description
 * @date 2020-06-22
 */
public class LazySingletonSafe {
    private static LazySingletonSafe lazySingletonUnsafe;


    /**
     * 私有化构造器
     */
    private LazySingletonSafe() {
        System.out.println("LazySingletonUnsafe构造器");
    }

    /**
     * 公有的静态获取实例方法 线程安全 但是效率低 因为每个通过getInstance() 获取的都要进入synchronized同步
     */
    public static synchronized LazySingletonSafe getInstance(){
        if(lazySingletonUnsafe==null){
            lazySingletonUnsafe = new LazySingletonSafe();
        }
        return lazySingletonUnsafe;
    }
}
